//罗马数字的枚举解法
public class B2 {
    public static int RomeNum(String s) {
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c=='I') sum+=1;
            if (c=='V') sum+=5;
            if (c=='X') sum+=10;
            if (c=='L') sum+=50;
            if (c=='C') sum+=100;
            if (c=='D') sum+=500;
            if (c=='M') sum+=1000;
        }
        //特殊处理：IV这些的情况，本来应该是4，却算成了6
        if (s.indexOf("IV")>=0) sum -=2;//字符串判断是否有子字符串用indexof
        if (s.indexOf("IX")>=0) sum -=2;
        if (s.indexOf("XL")>=0) sum -=20;
        if (s.indexOf("XC")>=0) sum -=20;
        if (s.indexOf("CD")>=0) sum -=200;
        if (s.indexOf("CM")>=0) sum -=200;

        return sum;
    }
    public static void main(String[] args) {
        System.out.println(RomeNum("MCCCXIV"));
    }
}
